package main;

import voidlib.*;
/**
 * @author nevidimov
 */
public class AccountController extends VoidController {

    public void loginAction() {
        if (!VoidUser.getInstance().isGuest()) {
            this.redirect(VoidConfig.rootUrl);
        }
        if (this.isPostRequest()) {
            String login = (String)this.request.getParameter("login");
            String password = (String)this.request.getParameter("password");
            if (VoidUser.getInstance().login(login, password)) {
                this.redirect(VoidConfig.rootUrl);
                return;
            } else {
                this.view.put("error", "Bad username / password");
            }
        }
        this.initModelAndView();
    }
    
    public void logoutAction() {
        VoidUser.getInstance().logout();
        this.redirect(VoidConfig.rootUrl);
    }
}
